package com.zhangh.summer.admin.support.multipleds;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @description: TODO
 * @author: zhanghui  zhanghlucky@163.com
 * @create: 2021-06-09 00:10
 **/
@Slf4j
public class DataSourceContextHolder {
    private static final ThreadLocal<String> contextHolder = new ThreadLocal();

    public DataSourceContextHolder() {
    }

    public static String getDataSourceType() {
        log.debug("Service get datasource currently is : [" + (String)contextHolder.get() + "]");
        return (String)contextHolder.get();
    }

    public static void setDataSourceType(String groupId) {
        contextHolder.set(groupId);
    }

    public static void clearDataSourceType() {
        contextHolder.remove();
    }
}
